import {IModel} from "./IModel";
/**
 * Created by ybjaa on 2017/6/23.
 */


/**
 * 实现了Imodel的通用类
 * 级别:实体类(m),通用(c)
 */
export class mc_modelImplement implements IModel{


    private c:any=null;

    constructor(private model:IModel){
        this.c=model.constructor;
    }


    /**
     * 浅克隆
     * @returns {IModel}
     */
    clone(): IModel {
        let newModel=new this.c();
        for (let p in this.model)
        {
            if( typeof (this.model[p])==("number"||"string")) {
                newModel[p]=this.model[p];
            }
        }

        return newModel;
    }


    /**
     *
     * 从实体类复制信息到本对象
     *
     * @param model 数据源
     * @returns {IModel} 返回本对象
     */
    copyFrom(model: IModel): IModel {

        if(!model) return this.model;

        for (let p in this.model)
        {
            if( typeof (this.model[p])==("number"||"string")) {
                if(model[p]!=undefined) {
                    this.model[p]=model[p];
                }
            }
        }
        return this.model;
    }
}